package com.wwp.tbshop.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SPUtils {
	public static final String FILENAME = "SPUtils";
	public static final String USERID = "userid"; // 保存 userid


	public static void putString(Context context,String key,String value){
		SharedPreferences sharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
		Editor edit = sharedPreferences.edit();
		edit.putString(key, value);
		edit.commit();
	}
	
	public static String getString(Context context,String key,String defValue){
		SharedPreferences sharedPreferences = UiUtil.sContext.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
		return sharedPreferences.getString(key, defValue);
	}
	
	public static void putBoolean(Context context,String key,boolean value){
		SharedPreferences sharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
		Editor edit = sharedPreferences.edit();
		edit.putBoolean(key, value);
		edit.commit();
	}
	
	public static int getInt(Context context,String key,int defValue){
		SharedPreferences sharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
		return sharedPreferences.getInt(key, defValue);
	}

	public static void putInt(Context context,String key,int value){
		SharedPreferences sharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
		Editor edit = sharedPreferences.edit();
		edit.putInt(key, value);
		edit.commit();
	}

	public static boolean getBoolean(Context context,String key,boolean defValue){
		SharedPreferences sharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean(key, defValue);
	}
	public static void putFloat(Context context,String key,float value){
		SharedPreferences sharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
		Editor edit = sharedPreferences.edit();
		edit.putFloat(key, value);
		edit.commit();
	}
	
	public static float getFloat(Context context,String key,float defValue){
		SharedPreferences sharedPreferences = context.getSharedPreferences(FILENAME, Context.MODE_PRIVATE);
		return sharedPreferences.getFloat(key, defValue);
	}

	public static String getUerid(){
        String string = getString(UiUtil.sContext, USERID, null);
        return string;
    }
}
